/**
 * @program: exchange
 * @description: toDo
 * @author: DengWei
 * @create: 2019-06-15
 **/
package com.exchange.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

/**
 * @program BeanUtil
 * @description 重新BeanUtil工具类
 * @author DengWei
 * @date 2019-06-15 17:54
 **/
public class BeanUtil extends cn.hutool.core.bean.BeanUtil {

    /**
     * 复制Listbean对象
     * @param from
     * @param target
     * @return
     */
    public static <T> List<T> copyListBean(List<?> from , Class target){

        try {
            List<Object> to = new ArrayList<>();

            if (!ObjectUtil.isEmpty(from)){
                for (Object object : from) {
                    if (!BeanUtil.isEmpty(object)){
                        Object toObject = target.newInstance();
                        BeanUtils.copyProperties(object,toObject);
                        to.add(toObject);
                    }
                }
            }
            return Convert.toList(target,to);
        }catch (Exception e){
            e.printStackTrace();
            return CollUtil.newArrayList();
        }

    }
}
